#!/usr/bin/python

import sys
from xml.dom.minidom import parse, parseString

xml_conf = '/home/lunmgr/lunmgr.conf.xml'
MODE = 'P2000_G3_FC'

def main(xml_file):
    dom = parse(xml_file)
    xml_root = dom.firstChild

    for elemRack in xml_root.getElementsByTagName('rack'):
      
        rackNumber = elemRack.getAttribute('number')
        print "#--------------- rack=%s ---------------" % rackNumber

        # only print port0
        elemPort0 = elemRack.getElementsByTagName('port')[0]

        #portNumber = elemPort0.getAttribute('number')
        #portWwn = elemPort0.getAttribute('wwpn')
            
        for elemEnc in elemPort0.getElementsByTagName('disk_enclosure'):
            encWwn = elemEnc.getAttribute('wwpn')

            for elemLun in elemEnc.getElementsByTagName('lun'):
                lunId = elemLun.getAttribute('id')

                if int(lunId) >=60: continue

                elemDevice = elemLun.getElementsByTagName('device')[0]
                elemMpath = elemLun.getElementsByTagName('mpath')[0]
                elemSize = elemLun.getElementsByTagName('size')[0]
                elemMountpt = elemLun.getElementsByTagName('mount_pt')[0]
                elemName = elemLun.getElementsByTagName('name')[0]

                print elemDevice.firstChild.data, MODE,
                print encWwn + ":" + lunId,
                print elemMountpt.firstChild.data, elemName.firstChild.data,
                print elemMpath.firstChild.data


if __name__ == '__main__':
    if len(sys.argv) > 1:
        xml_file = sys.argv[1]
    else:
        xml_file = xml_conf

    main(xml_file)
